using System;

// Plan to get the nearest enery pickup - won't return false(finish) until all energy is picked up
public class PlanGoToGoal : Plan
{

	private AgentBehaviourScript agent;
	private Maze maze;
	
	private Plan currentPlan = null;	

	public PlanGoToGoal (AgentBehaviourScript agent, Maze maze)
	{
		this.agent = agent;
		this.maze = maze;
	}
	
	public override bool execute()
	{
		if ( currentPlan == null || !currentPlan.execute() )
		{
			// no currentPlan or currentPlan finished
			currentPlan = new PlanPathFindToPosition(agent, maze, agent.getNearestExit());
		}
		
		return true;	
	}
	
	public override pathplanner getPathPlanner ()
	{
		if (currentPlan	!= null) {
			return currentPlan.getPathPlanner();
		} else {
			return null;
		}
	}

	public override string ToString ()
	{
		string returnString = string.Format ("getNearestExit( ");
		if (currentPlan != null)
			returnString += currentPlan.ToString();
		returnString += " )";
		return returnString;
	}	
	
	
}

